<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:em="http://xmlns.jcp.org/jsf/composite/ezcomp"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://xmlns.jcp.org/jsf/passthrough">
    <ui:composition template="/template.xhtml">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
        <ui:define name="title">
            <h:outputLabel value="#{messages.Knowledge}"></h:outputLabel>
        </ui:define>
        <ui:define name="body">
            <h:outputStylesheet library="css" name="dagre.css"/>
            <h:outputScript library="javaScript" name="wait.js" target="head"/>
            <h2 id="workingIndicator" style="display: none">
                <h:graphicImage library="images" name="pleaseWait.gif"/>
            </h2>
            <h:form styleClass="jsfcrud_list_form" prependId="false"> 
                <h:outputScript library="javaScript" name="d3.v4.js" target="head"/>
                <h:outputScript library="javaScript" name="graphlib-dot.js" target="head"/>
                <h:outputScript library="javaScript" name="dagre-d3.js" target="head"/>
                <h:messages  id="myMessage" errorStyle="color: red"  infoStyle="color: green"   fatalStyle="color: red"  layout="table"   styleClass="message"/>
                <h:panelGrid columns="3">
                    <h:inputText id="searchText" value="#{knowledgeController.searchName}" immediate="true">
                        <f:ajax render="search"/>
                    </h:inputText>
                    <h:commandButton id="search" value="#{messages.Search} #{messages.Knowledge}" action="#{knowledgeController.search()}" immediate="true">
                        <f:ajax render="@form" onevent="showWorkingIndicator"/>
                    </h:commandButton>
                </h:panelGrid>
                <h:panelGrid columns="1">
                    <em:majorSubjectTemplate/>
                </h:panelGrid>
                <h:panelGrid columns="1">
                    <h:selectManyListbox value="#{knowledgeController.selectedMany}" >
                        <f:selectItems value="#{knowledgeControllerA.getKnowledgeList4Subject(subjectController.selected)}" var="knowledge"
                                       itemLabel="#{knowledge.name}" itemValue="#{knowledge.id}"/>
                    </h:selectManyListbox>

                    <h:commandButton value="#{messages.Create}#{messages.PPT}" action="#{knowledgeController.createPPT()}"/>
                    <h:inputHidden p:id="inputGraph" p:name="inputGraph" value="#{knowledgeController.getKnowledgeRelationship4dagre()}" />
                    <input type="hidden" value="#{praiseController.msg}" id="msg"/>
                </h:panelGrid>
                <script>
                    function judgePraise() {
                        var msg = document.getElementById("msg");
                        if (msg.value !== '') {
                            alert(msg.value);
                        }
                    }
                </script>

                <svg width="960" height="600" id="svg"> <g/></svg>
                <script>
                    var svg = d3.select("svg"),
                            inner = d3.select("svg g"),
                            zoom = d3.zoom().on("zoom", function () {
                        inner.attr("transform", d3.event.transform);
                    });
                    svg.call(zoom);

                    // Create and configure the renderer
                    var render = dagreD3.render();

                    var g;
                    var inputGraph = document.querySelector("#inputGraph");
                    try {
                        g = graphlibDot.read(inputGraph.value);
                    } catch (e) {
                        inputGraph.setAttribute("class", "error");
                        throw e;
                    }

                    g.graph().transition = function (selection) {
                        return selection.transition().duration(500);
                    };

                    // Render the graph into svg g
                    d3.select("svg g").call(render, g);
                </script>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
